import {createRouter, createWebHashHistory} from 'vue-router'
import {cancelArr} from "@/utils/BSideRequest";

const routes = [{
    path: '/',
    name: 'Index',
    component: () => import('../views/EmployeeView.vue'),
},{
    path: '/user',
    name: 'UserView',
    component: ()=>import('../views/UserView.vue'),
},{
    path: '/account',
    name: 'AccountView',
    component: ()=>import('../views/AccountView.vue'),
},{
    path: '/about',
    name: 'AboutView',
    component: ()=>import('../views/AboutView.vue'),
}]

const router = createRouter({
    history: createWebHashHistory(),
    routes
})


// TODO 全局前置守卫
router.beforeEach(async (to) => {
    // TODO 页面切换中断所有请求
    cancelArr.forEach((cancel, index) => {
        cancel()
        cancelArr.splice(index, 1)
    })

    // TODO 设置浏览器Title
    document.title = (to.meta.title ? to.meta.title : '') + ' - H公司管理系统'
})

export default router
